<?php
    include_once('taskmodel.php');
    session_start(); // Starting Session
    $error=''; // Variable To Store Error Message
 
    if (isset($_POST['submit'])) {
        if (empty($_POST['username']) || empty($_POST['password'])) {
            $error = "Username or Password is invalid";
            echo $error;
        }
        else
        {
            
            // Define $username and $password
            $username=$_POST['username'];
            $password=$_POST['password'];

        
            // To protect MySQL injection for Security purpose
            //$username = stripslashes($username);
            //$password = stripslashes($password);
            //$username = mysql_real_escape_string($username);
            //$password = mysql_real_escape_string($password);
            echo $username.$password;
            // SQL query to fetch information of registerd users and finds user match.

            $rows = checkRegisteredUser($username,$password);
            echo $rows;
            if ($rows == 1) {
                $_SESSION['login_user']=$username; // Initializing Session
                $_SESSION['loggedin']=1;
                

                header("location: index.php"); // Redirecting To Other Page
            } else {
                $error = "Username or Password is invalid";
            }
        }
    }
?>